package gps;

import game.fiver.Fiver;
import game.fiver.heuristic.DiagFirst;
import game.fiver.rule.MovesMade;
import games.puzzle8.Puzzle8Problem;
import games.rolling.RollingProblem;
import gps.methods.astar.AStarMethod;
import gps.methods.dfs.DeepFirstMethod;
import gps.methods.dfs_inform.DfsInformMethod;
import gps.methods.ida_star.IdaStarMethod;
import gps.methods.uniform_cost.UniformCostMethod;
import gps.problem.FullBoardProblem;
import gps_api.Problem;

import java.util.Properties;


public class GpsApp{
	private Problem problem;
	private SolverMethod method;
	private ProductionSystem ps;

	public GpsApp() throws Exception{
		Properties configFile= new Properties();

		configFile.load(this.getClass().getClassLoader().getResourceAsStream("gps\\gps.conf"));
		setProblem(configFile.getProperty("problem"));
		setMethod(configFile.getProperty("method"));
		setLookOpenNodes(configFile.getProperty("lookOpenNodes"));
		setLookClosNodes(configFile.getProperty("lookCloseNodes"));

		ps= new ProductionSystem(problem, method);
	}

	public void run(){
		ps.runSystem();
	}

	private void setProblem(String arg) throws Exception{

		if(arg.equals("puzzle8")){
			problem= new Puzzle8Problem();
		}else if(arg.equals("rolling")){
			problem= new RollingProblem();
		}else if(arg.equals("fullboard")){
			problem= new FullBoardProblem();
		}else if(arg.equals("fiver")){
			problem= new Fiver(5, new DiagFirst(), new MovesMade());

		}else if(arg.equals("")){

		}
	}

	private void setMethod(String arg) throws Exception{
		if(arg.equals("dfs")){
			method= new DeepFirstMethod();
		}else if(arg.equals("uniform_cost")){
			method= new UniformCostMethod();
		}else if(arg.equals("dfs_inform")){
			method= new DfsInformMethod(problem);
		}else if(arg.equals("ida_star")){
			method= new IdaStarMethod(problem);
		}else {
			method= new AStarMethod(problem);
		}
	}

	private void setLookOpenNodes(String arg){
		if(arg.equals("true")){
			method.setLookOpenList(true);
		}else{
			method.setLookOpenList(false);
		}
	}

	private void setLookClosNodes(String arg){
		if(arg.equals("true")){
			method.setLookCloseList(true);
		}else{
			method.setLookCloseList(false);
		}
	}

	public static void main(String[] args){
		GpsApp gpsApp = null;
			try {
				gpsApp = new GpsApp();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			gpsApp.run();

	}

}
